package com.example.academicsystem.server.controller.admin;

import com.example.academicsystem.pojo.dto.AdminCourseDto;
import com.example.academicsystem.pojo.dto.CourseDeleteDto;
import com.example.academicsystem.pojo.dto.CourseInsertDto;
import com.example.academicsystem.pojo.dto.CourseUpdateDto;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.result.Result;
import com.example.academicsystem.server.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/course")
@Slf4j
public class AdminCourseController {
    @Autowired
    private AdminService adminService;

    /**
     * course 新增
     * */
    @PostMapping("/insert")
    public Result courseInsert(@RequestBody CourseInsertDto courseInsertDto){
        log.info("courseINSERT");
        adminService.courseInsert(courseInsertDto);
        return Result.success();
    }
    /**
     * course 删除 by courseid
    * */
    @DeleteMapping("/delete")
    public Result courseDelete(@RequestBody CourseDeleteDto courseDeleteDto){
        log.info("courseDelete");
        adminService.courseDelete(courseDeleteDto);
        return Result.success();
    }
    /**
    * 分页查询课程
    * */
    @PostMapping("/page")
    public Result<PageResult> coursePageQuery(@RequestBody AdminCourseDto adminCourseDto){
        log.info("coursePageQuery");
        PageResult pageResult= adminService.coursePageQuery(adminCourseDto);
        return Result.success(pageResult);
    }
    /**
     * 修改课程 by id
     * */
    @PutMapping("/update")
    public Result courseUpdate(@RequestBody CourseUpdateDto courseUpdateDto){
        log.info("courseUpdate");
        adminService.courseUpdate(courseUpdateDto);
        return Result.success();

    }
}
